 
 //页面初始化
 userInit();
 function userInit(){
 	var token=getToken();
	var name=getname(); 
	var head=gethead();
	var phone=getphone();
	
	
	if(name){
		$('#nickname').val(name);
		
	}
	if(head){
		$('#imgboxs').attr('src',head);
		
	}
 	var qq=getqq();
 	
 	var weixin=getweixin();
 	if(!phone){
 		$('#phone').attr('href','blind.html');
 		$('#phone div span').html('未绑定');
 	}
 	if(!qq){ 
 		  
 		$('.qq').attr('id','qq');
 		$('.qq a div span').html('未绑定');
 		$('#qq').click(function() { 
             
            authLogin('qq'); 
        }); 
 	}
 	if(!weixin){
 		$('.weixin').attr('id','weixin');
 		$('.weixin div span').html('未绑定');
 		$('#weixin').click(function(){
			authLogin('weixin');
		});
 	}
 	mui.plusReady(function() {   
            plus.oauth.getServices(function(services) { 
                auths = services; 
            }, function(e) { 
                alert("获取登录服务列表失败：" + e.message + " - " + e.code); 
            }); 
    })
 	
 	
 }
 
  
 $('#nickname').blur(function(){
 		var httpHost = getHttpHost();
 		var name=$('#nickname').val();
 		var token=getToken();
// 		alert(token);alert(name);
   		$.post(httpHost+'/index/Base/upname.html',{nickname:name,token:token},function(d){
                  				
                  				da=JSON.parse(d);
                  				if(da.code==400){
                  					alert('修改昵称成功');
									window.localStorage.setItem('token',d);
									window.location.reload();
                  				}
                  				
								
							
				    	})
 	})
       
        
        
 
        // 第三方登录操作 
        function authLogin(type) { 
        	
            var s; 
            for (var i = 0; i < auths.length; i++) { 
                if (auths[i].id == type) { 
                    s = auths[i]; 
                    break; 
                } 
            } 
            if (!s.authResult) { 
                s.login(function(e) { 
                    mui.alert("登录认证成功！"); 
                   
                    authUserInfo(type); 
                }, function(e) { 
                    mui.toast("登录认证失败！"); 
                }); 
            } else { 
                mui.toast("已经登录认证！"); 
            } 
        } 
        //注销 
        function authLogout() { 
            for (var i in auths) { 
                var s = auths[i]; 
                if (s.authResult) { 
                    s.logout(function(e) { 
//                      alert("注销登录认证成功！"); 
                    }, function(e) { 
                        console.log("注销登录认证失败！"); 
                    }); 
                } 
            } 
        } 
        // 微信登录认证信息 
        function authUserInfo(type) { 
            var s; 
            for (var i = 0; i < auths.length; i++) { 
                if (auths[i].id == type) { 
                    s = auths[i]; 
                    break; 
                } 
            } 
            if (!s.authResult) { 
                mui.toast("未授权登录！"); 
            } else { 
                s.getUserInfo(function(e) { 
                	var httpHost = getHttpHost();
                	var info=s.userInfo;
                	var token=getToken();
                	jQuery.support.cors = true;
                  	if(type=='qq'){
                  		var openid=JSON.stringify(s.authResult.openid);
                  		
                  		authLogout(); 
					    $.post(httpHost+'/index/Base/qqblind.html',{qq_openid:openid,token:token},function(d){
                  		
								da=JSON.parse(d);
								if(da.code==400){
									window.localStorage.setItem('token',d);
									window.location.reload();
								}else{
									alert(da.msg); 
								}
//								
							
				    	})
                  	}
                  
                  	if(type=='weixin'){
                  		var openid=JSON.stringify(info.openid);
                  		authLogout(); 
                  		
		            	$.post(httpHost+'/index/Base/wechablind.html',{weixin_openid:openid,token:token},function(d){
                  				da=JSON.parse(d);
                  				
                  				alert(d);
								if(da.code==400){
									window.localStorage.setItem('token',d);
									window.location.reload();
								}else{
									alert(da.msg);
								}
							
				    	})
                  	}
                  	
                  	
                  	
                     
                }, function(e) { 
                    alert("获取用户信息失败：" + e.message + " - " + e.code); 
                }); 
            } 
        }